<template>
  <div class="auth-wrapper">

  <el-dialog
    title="选择货物分类"
    :close-on-click-modal="false"
     v-dialogDrag
    width="400px"
    :visible.sync="visible">
    <el-form class="auth" :model="inputForm" status-icon v-loading="loading" ref="inputForm" @keyup.enter.native="inputFormSubmit()"
             @submit.native.prevent>
          <div class="auth-tree">
            <el-scrollbar style="height: 450px">
              <el-tree
                :check-strictly="true"
                :data="menuList"
                :props=" {
                                label: 'name',
                                children: 'children'
                              }"
                node-key="id"
                ref="menuListTree"
                :default-expanded-keys="['1']"
                :default-checked-keys="menuCheckedKeys"
                show-checkbox>
              </el-tree>
            </el-scrollbar>
          </div>
    </el-form>
     <span slot="footer" class="dialog-footer">
      <el-button type="primary" size="small" plain @click="inputFormSubmit()" v-noMoreClick>确定</el-button>
       <el-button @click="visible = false">取消</el-button>
    </span>
  </el-dialog>
  </div>
</template>

<script>
  import {getTreeData} from '@/api/market/product.js'
  export default {
    data () {
      return {
        visible: false,
        loading: false,
        title: '',
        menuList: [],
        dataRuleList: [],
        menuCheckedKeys: [],
        inputForm: {
          id: '',
          menuIds: '',
            endEquipId: '',
            endEquipCode: '',
            edgeEquipCode: '',
            state: -1
        }
      }
    },
    methods: {
    	handleClose(done) {
				this.$Msg.confirm({
					title:'您确定要关闭吗？',
					content:this.GLOBAL.FORM_CLOSE_TIPS,
					confirmCall:()=>{
						done();
					}
				})
			},
      init (inputForm) {
        this.visible = true
          this.inputForm = inputForm
          this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          this.$refs.menuListTree.setCheckedKeys([])
          this.getTreeData(0)
        })
      },
      getTreeData (id) {
        getTreeData({id: id}).then((res) => {
          if (res.data.code === '200') {
            this.menuList = res.data.result
              console.log(this.menuList)
          }
        })
      },
      // 表单提交
      inputFormSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          this.inputForm.menuIds = this.$refs.menuListTree.getCheckedKeys().concat(this.$refs.menuListTree.getHalfCheckedKeys()).join(',')
          if (valid) {
            this.loading = true
            this.$http({
              url: `/equip/equipProduct/save`,
              method: 'post',
              headers: {'Content-Type': 'application/json; charset=utf-8'},
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.$message.success(data.msg)
                this.visible = false
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
::v-deep  .el-tree-node{
    .is-leaf + .el-checkbox .el-checkbox__inner{
      display: inline-block;
    }
    .el-checkbox .el-checkbox__inner{
      display: none;
    }
  }
  .auth-wrapper{
    ::v-deep.el-dialog{
      .el-dialog__body{
        .el-scrollbar{
          margin-top: 5px;
        }
        .el-scrollbar__wrap{
          overflow: auto;
        }
        .auth-tree{
          background: #fff;
          border: 1px solid #dcdfe6;
          -webkit-box-shadow: 0 2px 4px 0 rgba(0,0,0,.12), 0 0 6px 0 rgba(0,0,0,.04);
          box-shadow: 0 2px 4px 0 rgba(0,0,0,.12), 0 0 6px 0 rgba(0,0,0,.04);
          padding: 20px;
        }
      }
    }
  }

  .el-tree {
    min-width: 100%;
    display: inline-block !important;
  }

  .el-scrollbar {
    height: 100%;
  }

</style>
